package jnBase.view
{
	import jnBase.Data;
	import jnBase.eventdispatcher.JNEventDispatcher;
	
	import laya.events.Event;
	import laya.utils.Handler;
	import laya.utils.Tween;
	
	import ui.tools.step_upUI;

	/**
	 *操作步骤显示view 
	 * @author Administrator
	 * 
	 */	
	public class StepControl extends step_upUI
	{
		private var endY:int;
		public var value:int;
		private var des:String;
		public function StepControl($i:int,$des:String)
		{
			super();
			this.mouseThrough=true;
			width=196;
			des=$des;
			value=$i;
			endY=value%2==0?0:75;
		}
		
		override public function onAwake():void
		{
			// TODO Auto Generated method stub
			super.onAwake();
			if(value==Data.currStep){
				redo.visible=true;
				select=true;
				SceneToolControl.getInstance().currStepBtn=this;
				JNEventDispatcher.getInstance().event(JNEventDispatcher.CLICK_ADD_PAGE);
			}
			else{
				select=false;
				redo.visible=false;
			}
			show();
			txt.text=des;
			if(des.length>8){
				txt.fontSize=148/(des.length-1);
				txt.valign="middle";
			}
			redo.on(Event.CLICK,this,redoClick);
		}
		private var isredo:Boolean=false;
		private function redoClick():void
		{
			// TODO Auto Generated method stub
			if(isredo) return ;
			isredo=true;
			Laya.timer.once(800,this,function():void{
				isredo=false;
			});
			JNEventDispatcher.getInstance().event(JNEventDispatcher.RE_DO);
		}
		public function set select($b:Boolean):void{
			btn.selected=dot.selected=$b;
			redo.visible=$b;
		}
		/**
		 *显示步骤 
		 * 
		 */		
		public function show():void{
			Tween.clearAll(btn);
			Tween.clearAll(dot);
			this.visible=true;
			btn.alpha=0;
			dot.alpha=0;
			dot.scale(1.5,1.5);
			Tween.to(btn,{y:endY,alpha:1},100);
			Tween.to(redo,{y:endY,alpha:1},100);
			Tween.to(dot,{scaleX:0.7,scaleY:0.7,alpha:1},100);
		}
		/**
		 *隐藏步骤 
		 * 
		 */		
		public function hide():void{
			Tween.clearAll(btn);
			Tween.clearAll(dot);
			Tween.to(btn,{y:35,alpha:0},100);
			Tween.to(redo,{y:35,alpha:0},100);
			Tween.to(dot,{scaleX:1.5,scaleY:1.5,alpha:0},100,null,Handler.create(this,end));
			function end():void{
				this.visible=false;
			}
		}
		
	}
}